<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="${res_app}/css/wuxi.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res}/js/public.js"></script>
<script type="text/javascript" src="${res_app}/js/app/proposal/irisPrpPrepare.js"></script>
<title>申请书审核</title>
<style type="text/css">
.button_orange { 
	height:25px; font-size:12px; color:#cc3300; border:1px #cc9933 solid; 
	background:url(${res}/images/button_orange.gif); padding:0 15px; *padding:0 10px;
	_padding:0 10px; cursor: pointer;
}
</style>
</head>
<body>
<%-- <security:authorize ifAnyGranted="A_AUTH_SCS">
 <cpt:helpTips key="prpapproveTips4scs" id="prpapproveTips4scs"></cpt:helpTips>
 <div class="clear_h10"></div>
 </security:authorize> --%>
	<input type="hidden" id="childDiv" class="thickbox" />
		<form method="post" id="mainForm">
			<input type="hidden" id="prpCodes" name="prpCodes" value="" />
			<input type="hidden" id="type" name="type" value="" />
		</form>
	<div class="soBox">
		<div class="detail ico_search">
			<table>
				<tr>
					<td rowspan="2"><strong>检索条件：</strong>
					</td>
					
						<td>
						<security:authorize ifNotGranted="A_AUTH_ADMIN">
							<cpt:search key="prpApprove_search_chushi"  repeatColumn="3" displayCount="6" leftStyle="width:100px"></cpt:search>
						</security:authorize> 
						
						<security:authorize ifAnyGranted="A_AUTH_ADMIN">
							<cpt:search key="prpApprove_search_chushi_1"  repeatColumn="3" displayCount="6" leftStyle="width:100px"></cpt:search>
						</security:authorize> 
						</td>
					
				</tr>
				<tr>
				<td>
					<div class="clear_h10"></div>
					<input type='button' id='searchBt' class="button_an" value='查询' />
				</td>
				</tr>
				
			</table>
		</div>
	</div>
	<div class="clear_h10"></div>
	<div>
		<div id='TopBarMnt'></div>
		<table id='dataGrid'></table>
		<div id='dataBar'></div>
	</div>
	<script type="text/javascript">
	var irisGrid = new IrisGrid("dataGrid", "dataBar", 'TopBarMnt');
	var prcWin = new progressWin("${res}");//初始化遮罩层
	
	var getSelOpt = function() {
		var g = "";
		$("input:checkbox[id^=jqg_dataGrid_]").each(function(i, obj) {
			if (obj.checked) {
				g += "," + obj.id.replace("jqg_dataGrid_", "");
			}
		});
		if (g != "") {
			g = g.substring(1);
		}
		return $.trim(g);
	};
	
	function ApproveDialog(type, gridObj, selectIdArray, recordRows){
		var prpCodes= getSelOpt();
		if(recordRows==''){
			prpCodes=selectIdArray+'';
		}
		if(prpCodes==""){
			scmError("请选择一条记录");
			return false;
		}
		
		
		if(type=="approve"){
				
				var url="${ctx}/prpapprove/openprpapprovedialog_pf?pf=1&category=A&status=01&prpCodes="+selectIdArray+"&type="+type+"&subGrantCode=0&TB_iframe=true&height=450&width=1000";
				var title="申报批复意见（最多为500字）";
				showThickBox(url,title);
				
			
		}
		
	}
	
	function checkSelect(selectArray){
		var checked = 1;
		$("#approve").removeAttr("disabled");//去除该属性
		var grantcodeStr = "";
		var statYearStr = "";
		for(var i=0;i<selectArray.length;i++){
			var status=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"13");
			var flagCan=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"14");
			var grantCode=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"15");
			var statyear=irisGrid.getGridDom().jqGrid('getCell',selectArray[i],"16");
			if(status=="05"){
				scmWarn("您所选择的这"+selectArray.length+"份申请书中有部分申请书已受理，不允许重复确认!");
				checked = 0;
				break;
			}else if(status=='04'&&flagCan=="0") {
				scmWarn("您所选择的这"+selectArray.length+"份申请书中有部分申请书的正式PDF未生成，请在生成之后再选择该申请书进行受理操作");
				checked = 0;
				break;
			}else{
				grantcodeStr += ","+grantCode;
				statYearStr += ","+statyear;
			}
		}
		if(checked==0){
			return false;
		}else if(grantcodeStr!=""){
			return checklimitInfo(grantcodeStr,statYearStr);
		}
		return true;
	}
	
	function closeDialog(){
		tb_remove();
	}

	
		/** 表格初始化**/
		//loadIrisGrid("${res}");
		function buildGrid() {
			
			var columnAttrList = new Array();
			
	
			
			columnAttr = new ColumnAttr("项目类别", "grant_name","grant_name", 4, "left", true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("项目名称", "zh_title","zh_title", 4, "left", true);//表头，字段名，，，宽度比例，居左，是否需要表头排序
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("受理编号", "prp_no","prp_no", 4, "left", true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("申报单位", "org_name","org_name", 4, "left", true);//表头，字段名，，，宽度比例，居左，是否需要表头排序
			columnAttrList.push(columnAttr);
			
		
			columnAttr = new ColumnAttr("单位法人", "psn_name","psn_name", 2, "center", true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("归口管理部门", "rec_org_name","rec_org_name", 4, "center", true);
			columnAttrList.push(columnAttr);
			
			/* columnAttr = new ColumnAttr("提交时间", "submitDate", "submit_date", 3,"left", true);
			columnAttrList.push(columnAttr); */
			
			columnAttr = new ColumnAttr("水印号", "prp_version","prp_version", 3, "left", true);
			columnAttrList.push(columnAttr);
			
			<security:authorize ifAnyGranted="A_AUTH_ADMIN">
			columnAttr = new ColumnAttr("项目比对", "fitCompare", "fitCompare", 3,"center", false, false, "text", false,true);
			columnAttrList.push(columnAttr);
			</security:authorize>
			
			
			columnAttr = new ColumnAttr("审核意见", "comment", "comment", 3,"center", false);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("PDF", "pdf", "pdf", 3,"center", false);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("操作", "", "", 3,"center", false);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("status", "status", "status", 3,"left", false,false,"text",true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("flagCan", "flagCan", "flagCan", 3,"left", false,false,"text",true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("grantCode", "grantCode", "grantCode", 3,"left", false,false,"text",true);
			columnAttrList.push(columnAttr);
			columnAttr = new ColumnAttr("statYear", "statYear", "statYear", 3,"left", false,false,"text",true);
			columnAttrList.push(columnAttr);
			
			
			
			columnAttr = new ColumnAttr("posCode", "posCode", "posCode", 3,"left", false,false,"text",true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("grantCode", "grantCode", "grantCode", 3,"left", false,false,"text",true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("subGrantCode", "subGrantCode", "subGrantCode", 3,"left", false,false,"text",true);
			columnAttrList.push(columnAttr);
			
			columnAttr = new ColumnAttr("prpCode", "", "", 3,"left", false,false,"text",true);
			columnAttrList.push(columnAttr);

		
			irisGrid.setColumnAttrs(columnAttrList);
			//打印汇总表功能关闭  
			 irisGrid.setToolsBar([ 
			   {
				  id : 'report',
				  name : ' 批 复 ',
				  trigger : function(gridObj, selectIdArray, recordRows){//按钮onclick方法
					  ApproveDialog("approve", gridObj, selectIdArray, recordRows);
				}
			   }]);
			 
			irisGrid.setUrl("${ctx}/prpapprove/list-for-cs?stat_year=${param.stat_year}");//查询url
			irisGrid.setCaption("暂写");
			irisGrid.setDefaultSortName("status,NLSSORT(zh_title,'NLS_SORT = SCHINESE_PINYIN_M')");//默认排序字段
			irisGrid.setDefaultSortorder("asc");
			irisGrid.setWidth(978);//整个表格宽度
			irisGrid.setCheckAble(true);//表格左边是否要复选框
			irisGrid.setShowRowIndex(true);//是否显示行号
			irisGrid.setQueryBox('searchBt', 'prpApprove_search_chushi');//查询条件 按钮名，查询条件function_key
			irisGrid.setLoadComplete(setGray);
			irisGrid.onSelectAll = function(selectid,isSelect){//全选事件
				//checkSelectAll();
			};
		
			irisGrid.build();
		}
		function showApproveDialog(pcode){
			var selectid= pcode;
			var curDate = "${curDate}";
			var roleId = "${roleId}";
			var off_code = "${off_code}";
			var posCode = $("#posCode_"+selectid).val();
			var grantCode = $("#grantCode_"+selectid).val();
			var subGrantCode = $("#subGrantCode_"+selectid).val();
			var status = $("#status_"+selectid).text();
			var dialogUrl = "${ctx}/prpapprove/openprpapprovedialog_pf?pf=1&category=A&off_code="+off_code+"&roleId="+roleId+"&status="+status+"&curDate="+curDate+"&prpCodes="+pcode+"&posCode="+posCode+"&grantCode="+grantCode+"&subGrantCode="+subGrantCode+"&TB_iframe=true&height=250&width=480";
		    window.open(dialogUrl,'newwin');
			
		}
		
		function checkSelectAll(){
			$("input:checkbox[id^=jqg_dataGrid_]").each(function(i, obj) {
				if($(obj).attr("disabled")){
					$(obj).attr("checked",false);
				}
			});
		}
		jQuery(function() {
			if("${prpstatus}"!=""){
				try{
				$("#_dyn_criteria2_field").val("prpstatus");
				_dyn_ShowCriteriaTag(document.getElementById("_dyn_criteria2_field"));
				$("#prpstatus").val("${prpstatus}");
				}catch(ee){}
			}
			
			if("${audie_date}"!=""){
				try{
				$("#_dyn_criteria2_field").val("audie_date");
				_dyn_ShowCriteriaTag(document.getElementById("_dyn_criteria2_field"));
				$("#audie_date").val("${audie_date}");
				}catch(ee){}
			}
			
			buildGrid();
		//	if($.browser.msie && $.browser.version<8)
			//	$("#return").addClass("button_orange").css("margin-left","166px");
		//	else
			//	$("#return").addClass("button_orange").css("margin-left","157px");
			
		});
		/** 表格初始化**/
		
		function setGray(){
			
		}
		
		function cleanQueryBox(){
			$("[id^='_dyn_criteria'][id$='_c']", "#prpApprove_search4org").each(function(){
				$(this).children().each(function(){
					$(this).val('');
				});
			});
		}
		
		function viewComment(des3Prpcode){
			var url="${ctx}/proposal/view/audit-comment-view?posCode="+des3Prpcode+"&TB_iframe=true&height=390&width=720";
			var title="审核意见";
			showThickBox(url,title);	
		}
		
		/**检查选中项目限项设置**/
		function checklimitInfo(grantcodeStr,statYearStr){
			var checked = 1;
			var msg = "";
			if(grantcodeStr!=""&&'${limitinfo}'!=''){
				grantcodeStr = grantcodeStr.substring(1);
				statYearStr = statYearStr.substring(1);
				var linfoArr = '${limitinfo}'.split(",");
				for(var i=0;i<linfoArr.length;i++){
					var sublinfoArr = linfoArr[i].split("##");//grant_code##grant_name##limit_count##approved_count
					var grantCode1 = sublinfoArr[0];
					var grantName = sublinfoArr[1];
					var limitCount = sublinfoArr[2];
					var approvedCount = sublinfoArr[3];
					var statYear = sublinfoArr[4];
					var grantcodeArr = grantcodeStr.split(",");
					var statYearArr = statYearStr.split(",");
					var selected = 0;
					for(var j=0;j<grantcodeArr.length;j++){
						if(grantcodeArr[j]==grantCode1 && statYearArr[j]==statYear){
							selected++;
						}
					}
					if(selected>0){
					var checkNum = parseInt(approvedCount)+selected;
						if(checkNum>parseInt(limitCount)){
							checked = 0;
							var shen = parseInt(limitCount,10)-parseInt(approvedCount,10);
							if(shen<0){
								shen = 0;
							}
							msg = "您单位申报"+statYear+"年度"+grantName+"类别的项目仅能申报"+limitCount+"项，目前已经上报了"+approvedCount+"项，还能上报"+shen+"项.";
							break;
						}
					}
				}
			}
			if(checked>0){
				return true;
			}
			scmWarn(msg, null, 7000);
			return false;
			
		}

		//审核页面调用该方法刷新页面
		function search(){
			$("#searchBt").click();
		}
		
		
		/**查看单位信息*/
		function orgInfoView(orgCode){
			//$("#orgCode").val(orgCode);
			//$("#mainForm").submit();
			tb_show("查看单位信息","${ctx}/orgmanage/verifyorg/org-info-view?orgCode=" + orgCode
					+ "&TB_iframe=true&height=460&width=950", false);
		}
		
		function showReportDialog(){
			var searchString=jQuery('#dataGrid').jqGrid('getGridParam','postData')['searchString'];
			tb_show("打印汇总表","${ctx}/prpapprove/list-for-report"+"?searchString="+encodeURIComponent(searchString)+"&TB_iframe=true&height=460&width=1024", false);
		}
		
		function viewPrpCheckResults(prpCode){
			tb_show("规则检查结果","${ctx}/prpapprove/prp-check-result?prpCode=" + prpCode
					+ "&TB_iframe=true&height=460&width=824", false);
		}
		
		function showPrpSimilarView(prpCode){
			tb_show("","${ctx}/prpapprove/prp-similar-list?prpCode=" + prpCode +"&TB_iframe=true&height=460&width=820",false);
		}
		/**查看单位信息*/
		function orgResembleView(orgCode,prpCode){
			//$("#orgCode").val(orgCode);
			//$("#mainForm").submit();
			var height = window.screen.height;
            var width = window.screen.width;
			tb_show("查看疑似单位信息","${ctx}/prpapprove/list-resemble-org?orgCode=" + orgCode
					+"&prpCode="+prpCode
					+"&TB_iframe=true&height="+height*0.8+"&width="+width*0.9+"", false);
		}
	</script>
</body>
</html>